package com.scau.ums.controller;

import com.github.pagehelper.PageInfo;
import com.scau.ums.model.Info;
import com.scau.ums.service.imp.info.InfoImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AlertInfoController {

    @Autowired
    private InfoImp infoImp;



    @RequestMapping(value = "/AlertInfo")
    public  String  AlertInfo(){
        return "AlertInfo";
    }

    @RequestMapping(value = "/AlertUncheckedInfo")
    public String AlertUncheckedInfo(HttpServletRequest request,@RequestParam(value = "currentPage",required=false,defaultValue="1")Integer currentPage){

        String receiverId = (String) request.getSession().getAttribute("USER_ID");

        List<Info> uncheckedInfoList = infoImp.getUncheckedInfoList(receiverId,currentPage);
        PageInfo<Info> pageInfo = new PageInfo<Info>(uncheckedInfoList);

        request.setAttribute("uncheckedInfoList",uncheckedInfoList);
        request.setAttribute("pageInfo",pageInfo);

        return "AlertUncheckedInfo";
    }

    @RequestMapping(value = "/AlertAllInfo")
    public String AlertAllInfo(HttpServletRequest request,@RequestParam(value = "currentPage",required=false,defaultValue="1")Integer currentPage){

        String receiverId = (String) request.getSession().getAttribute("USER_ID");

        List<Info> AllInfoList = infoImp.getAllInfoList(receiverId,currentPage);
        PageInfo<Info> pageInfo = new PageInfo<Info>(AllInfoList);

        request.setAttribute("AllInfoList",AllInfoList);
        request.setAttribute("pageInfo",pageInfo);

        return "AlertAllInfo";
    }

    @RequestMapping(value = "/showSpecifiedInfo")
    public  String  showSpecifiedInfo(HttpServletRequest request,Integer InfoId){
        Info specifiedInfo = infoImp.getSpecifiedInfo(InfoId);
        infoImp.InfoIsChecked(InfoId);
        request.setAttribute("specifiedInfo",specifiedInfo);
        return "showSpecifiedInfo";
    }
}
